package top.kaoshanji.p2ch06b;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.p2ch06b.support.MyBean;
import top.kaoshanji.u1constant.FileConstant;

import java.beans.XMLEncoder;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * 代码清单 p2ch06b-07：XMLEncoder类的新的构造方法的使用示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/19 16:31
 */
public class XMLEncoderExample01 {

    private static final Logger logger = LogManager.getLogger(XMLEncoderExample01.class);

    public static void main(String[] args) throws IOException {
        logger.info("...代码清单 p2ch06b-07：XMLEncoder类的新的构造方法的使用示例...");

        OutputStream output = Files.newOutputStream(Paths.get(FileConstant.LOCAL_ROOT_PATH.concat("p2ch06b07-result.xml")),
                StandardOpenOption.CREATE_NEW);

        MyBean myBean = new MyBean();
        myBean.setName("xxxppp");

        try (XMLEncoder encoder = new XMLEncoder(output, StandardCharsets.UTF_8.name(), true, 0)){
            encoder.writeObject(myBean);
        }

    }

}
